package org.keyuan.util;

public class WebTool {
	
  public static PageIndex getPageIndex(int viewpagecount, int currenPage, int totalpage){

		int startpage = currenPage-(viewpagecount%2==0? viewpagecount/2-1 : viewpagecount/2);
		int endpage = currenPage+viewpagecount/2;
		if(startpage<1){
			startpage = 1;
			if(totalpage>=viewpagecount) endpage = viewpagecount;
			else endpage = totalpage;
		}
		if(endpage>totalpage){
			endpage = totalpage;
			if((endpage-viewpagecount)>0) startpage = endpage-viewpagecount+1;
			else startpage = 1;
		}
		
		return new PageIndex(startpage, endpage);		
  }
}
